package com.wandian.weather.adapter;

import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mylib.libcore.utils.TimeFormate;
import com.wandian.weather.R;
import com.wandian.weather.bean.WeatherInformationBean;
import com.wandian.weather.tools.WeatherUtil;

/**
 * @author cl
 * @date 2020-08-27
 * @description WeatherFifteenDayRecycleAdapter
 **/
public class WeatherFifteenDayRecycleAdapter extends BaseQuickAdapter<WeatherInformationBean.Weather30Bean, BaseViewHolder> {

    private int selectPos;
    public WeatherFifteenDayRecycleAdapter(int layoutResId) {
        super(layoutResId);
    }
    public void setSelectPos(int selectPos) {
        this.selectPos = selectPos;
    }

    public int getSelectPos() {
        return selectPos;
    }


    @Override
    protected void convert(BaseViewHolder helper, WeatherInformationBean.Weather30Bean item) {
        try {
            LinearLayout rootView = helper.getView(R.id.ll_item_new15days_weather_root);
            TextView tvWeek = helper.getView(R.id.tv_item_new15days_weather_week);
            TextView tvDate = helper.getView(R.id.tv_item_new15days_weather_date);
            if(helper.getLayoutPosition() == selectPos){
                rootView.setBackgroundResource(R.drawable.button_transparent_two_circle_solid_selector_6);
                tvWeek.setTextColor(mContext.getResources().getColor(R.color.white));
                tvDate.setTextColor(mContext.getResources().getColor(R.color.white));
            }else {
                rootView.setBackgroundResource(R.color.transparent);
                tvWeek.setTextColor(mContext.getResources().getColor(R.color.white80));
                tvDate.setTextColor(mContext.getResources().getColor(R.color.white80));
            }

            if(helper.getPosition() == 0)
                helper.setText(R.id.tv_item_new15days_weather_week, "今天");
            else if(helper.getPosition() == 1)
                helper.setText(R.id.tv_item_new15days_weather_week, "明天");
            else {
                helper.setText(R.id.tv_item_new15days_weather_week, item.getWeek().replace("星期", "周"));
            }
            String date = TimeFormate.timeStringToTimeString(item.getDate(), "MM月dd日", "MM/dd");
            helper.setText(R.id.tv_item_new15days_weather_date, date);
            int res = WeatherUtil.getWeatherStateImage(item.getImg_num(), false);
            helper.setImageResource(R.id.img_item_new15days_weather, res);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
